package framework.graphics;

import javax.microedition.khronos.opengles.GL10;

public class Animation extends Presentation {

	protected float delay;
	protected int framesQuant;
	protected Texture[] frames;
	
	protected int currentFrame = 0;
	protected float currentTime = 0;
	
	public Animation(float delay, Texture[] frames) {
		this.delay = delay;
		this.framesQuant = frames.length;
		this.frames = frames;
		this.height = frames[0].getHeight();
		this.width = frames[0].getWidth();
	}
	
	public void draw(float deltaTime, GL10 gl, float x, float y) {
		updateFrames(deltaTime);
		frames[currentFrame].draw(deltaTime, gl, x, y);
	}
	
	protected void updateFrames(float deltaTime) {
		currentTime += deltaTime;
		if (currentTime > delay) {
			if (currentFrame != framesQuant - 1) {
				currentFrame++;
			} else {
				currentFrame = 0;
			}
			currentTime -= delay;
		}
	}
	
}
